package com.ucap.weking.guangan.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ucap.weking.guangan.R;
import com.ucap.weking.guangan.bean.ListLIveReplyBean;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by weking on 2017/11/16.
 */

public class ListSpeakAdapter extends BaseAdapter {
    ArrayList<ListLIveReplyBean.RowsBean> mData;

    public ListSpeakAdapter(ArrayList<ListLIveReplyBean.RowsBean> mData) {
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public ListLIveReplyBean.RowsBean getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_live_online_fragment_1, null);
            holder = new Holder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        ListLIveReplyBean.RowsBean item = getItem(position);
        holder.tvName.setText(item.getNAME() + ":    ");
        holder.tvContent.setText(item.getCONTENT());
        if (!TextUtils.isEmpty(item.getREPLYNAME())) {
            holder.tvReplyName.setText("(已回复" + item.getREPLYTIME() + ")" + item.getREPLYNAME());
            holder.tvReplyContent.setText(item.getREPLYCONTENT());
            holder.tvReplyName.setVisibility(View.VISIBLE);
            holder.tvReplyContent.setVisibility(View.VISIBLE);
        } else {
            holder.tvReplyName.setVisibility(View.GONE);
            holder.tvReplyContent.setVisibility(View.GONE);
        }
        return convertView;
    }

    class Holder {
        @InjectView(R.id.tv_name)
        TextView tvName;//提问者名字
        @InjectView(R.id.tv_content)
        TextView tvContent;//提问着内容
        @InjectView(R.id.tv_reply_name)
        TextView tvReplyName;//回答者名字和时间
        @InjectView(R.id.tv_reply_content)
        TextView tvReplyContent;//回答内容

        public Holder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
